package com.sqx.modules.sysUserAddress.controller;

import com.sqx.common.utils.Result;
import com.sqx.modules.sysUserAddress.entity.SysUserAddress;
import com.sqx.modules.sysUserAddress.service.ISysUserAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wuChang
 * @since 2023-08-10
 */
@RestController
@RequestMapping("/admin/address/")
@Api(value = "用户地址", tags = {"用户地址"})
public class AdminUserAddressController {

    @Autowired
    private ISysUserAddressService userAddressService;

    @ApiOperation("保存地址")
    @PostMapping("saveAddress")
    public Result saveAddress(Long userId, SysUserAddress sysUserAddress) {
        sysUserAddress.setUserId(userId);
        return userAddressService.saveAddress(sysUserAddress);
    }

    @ApiOperation("获取地址详细信息")
    @GetMapping("getAddressInfo")
    public Result getAddressInfo(Long addressId) {

        return Result.success().put("data", userAddressService.getById(addressId));
    }

    @ApiOperation("删除地址")
    @PostMapping("deleteAddress")
    public Result deleteAddress(Long addressId) {
        return userAddressService.removeById(addressId) ? Result.success() : Result.error();
    }

    @ApiOperation("获取地址列表")
    @GetMapping("getAddressList")
    public Result getAddressList(Long userId, Integer page, Integer limit, SysUserAddress sysUserAddress) {
        sysUserAddress.setUserId(userId);
        return Result.success().put("data", userAddressService.getAddressList(page, limit, sysUserAddress));
    }
}
